<?php
ini_set("display_errors", "On"); 
error_reporting(E_ALL);

define('IN_WONDERSHARE', true);
header("Content-type:text/html;charset=utf-8");
require('../conf/conf.php');
require('../includes/init.php');
require('./configs/site_config.php');
require('./classes/module/module_author.php');

class Author {
	private $mod;
	private $uid;
	
	public function __construct(){
		$this->uid = $_SESSION['AID'];
		$this->mod = new AuthorModule();
	}
	
	
	//note 列表
	public function index(){
		$data = $this->mod->get_list( $this->uid );
		$GLOBALS['smarty']->assign('data', $data);
		$GLOBALS['smarty']->display('author_list.htm');
	}
	
	
	//note 添加
	public function add(){
		if( isset($_POST['ispost']) ){
			$r = $this->mod->add( $this->uid, $_POST['author'], $_POST['email'], $_POST['avatar'], $_POST['gaccount'] );
			echo '<script>alert("添加成功！");document.location.href="author.php"</script>';
			exit;
		}
		$GLOBALS['smarty']->display('author_add.htm');  
	}
	
	//note 编辑
	public function edit(){
		$aid = $_GET['aid'];		
		if( isset($_POST['ispost']) ){
			//删除队列
			queueDelete(0, $aid);
			
			$r = $this->mod->update( $aid, $_POST['author'], $_POST['email'], $_POST['avatar'], $_POST['gaccount'] );
			
			//修改相关联文章模板的修改时间
			$update_arr = array('author_id' => $aid,
								'operation_type' => 'author',
								'is_ajax' => 1
			 );
			 
			file_get_contents("http://cms.wondershare.com/wondershare/template.php?action=updateTemplate&type=update&".
										http_build_query($update_arr));					
			echo '<script>alert("编辑成功！");document.location.href="author.php"</script>';
			exit;
		}else{
			//加入队列
			queueInfo($aid);
		}

		$data = $this->mod->get_one( $aid );
		$GLOBALS['smarty']->assign('data', $data);
		$GLOBALS['smarty']->display('author_add.htm');  
	}
	
	//note 删除
	public function del(){
		$aid = $_GET['aid'];
		$this->mod->del( $aid );
		echo '<script>alert("删除成功！");document.location.href="author.php"</script>';
	}
	
	
	
	
	
	
}


$act = isset($_GET['action']) ? $_GET['action'] : 'index';
$app = new Author();

if( method_exists( $app, $act ) ){
	$app->$act();
}else{
	echo 'no this function';
}